# 类
# 定义
class Student():
    # 初始化方法
    def __init__(self, cid, cname, cage, cclazz):
        # 定义属性 并进行赋值（初始化）
        self.id = cid
        self.name = cname
        self.age = cage
        self.clazz = cclazz
        # 如果不想被访问 可以在属性名前加上两个 下划线__
        self.__secret = '这是一个秘密'

    # 类的方法
    # 检测以下age是否为空
    def missing_detecting(self):
        if self.age == '':
            print("age值缺失")
        else:
            print("age没有缺失")


# 创建对象
stu1 = Student('001', 'zhangSan', '20', '文科一班')
# 获取属性
print(stu1.id)
print(stu1.name)
print(stu1.age)
print(stu1.clazz)
print("取出隐藏的属性", stu1._Student__secret)
# print(stu1.secret)
# print(stu1.__secret)
# 调用方法
stu1.missing_detecting()


# 继承
class Animal():
    def __init__(self):
        self.name = "animal"

    def run(self):
        print("Animal is running")


class Dog(Animal):
    def run(self):
        print("Dog is running")


class Cat(Animal):
    def run(self):
        print("Cat is running")


a = Animal()
b = Dog()
c = Cat()
print(b.name)

a.run()
b.run()
c.run()

# 多态
# 父类引用指向子类对象
print(isinstance(a, Animal))
print(isinstance(b, Dog))
print(isinstance(c, Cat))
print(isinstance(b, Animal))


def run_twice(animal):
    animal.run()
    animal.run()


run_twice(a)
run_twice(b)
run_twice(c)
